$(document).ready(function()
{
    loadEvent();
})


function loadEvent(){
     $.getJSON("./displayCollection").done(function(events){
        console.log(events);
        Eventdisplay(events);
     }).fail(function(e){
        console.log(e);
     });
}


function Eventdisplay(events){


        var table = $("<table #eventView class ='event'></table>");
         var tr = $("<tr></tr>");
          tr.append("<td>日期</td>");
          tr.append("<td>记录</td>");
          tr.append("<td>图片</td>");
          tr.append("<td>取消收藏</td>");

         table.append(tr);

         for(var event of events){
              var tr = $("<tr></tr>");
              tr.append("<td>"+event.date+"</td>");
              tr.append("<td>"+event.event+"</td>");
              tr.append("<td>"+"<img src='./image/upload/" + event.picture + "' class = event-pic/>"+"</td>");
              tr.append( "<td><a href='deleteFromCollection?eventId="+event.id+"'>取消收藏</a></td>" );
              table.append(tr);
        }
              $("#eventView").empty().append(table);
}